<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    {include file="/layout/scriptload"}
    <title>图片素材</title>
    <style>
        .img_list{
            width:78px;height:42px;cursor:pointer
        }
    </style>
</head>
<body>
<div class="box">
    <section class="content-header">
        <ol class="breadcrumb">
            <li><a><i class="fa fa-dashboard"></i> 素材管理</a></li>
            <li class="active">图片素材列表</li>
        </ol>
    </section>
    <!-- /.box-header -->
    <section class="content">
        <div class="box-body">
            <div id="example1_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
                <div class="row">
                    <div class="col-sm-12">
                        <div id="example1_filter" class="dataTables_length">
                            <button type="button" onclick="relist()" title="刷新" class="btn bg-aqua margin"><i class="fa fa-refresh"></i></button>
                            <button type="button" onclick="toadd()" class="btn margin" style="background: #18bc9c;color: #ffffff;">添加</button>
                            <button type="button" onclick="todel()" id="btn_del" class="btn bg-red margin"><i class="fa  fa-trash-o"></i> 删除</button>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-12">
                        <table id="example1" class="table table-bordered table-striped dataTable" role="grid" aria-describedby="example1_info">
                            <thead>
                            <tr role="row">
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 60px;">
                                    <input id="allchecked" type="checkbox" style="margin-left: 10px">
                                </th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 500px;">图片</th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 140px;">图片位置</th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 140px;">总分类</th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 140px">子分类</th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 140px;">账号池</th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 200px;">创建时间</th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 140px;">操作</th>
                            </tr>
                            </thead>
                            <tbody id="tb">
                            </tbody>
                        </table>
                        <div class="layui-row pull-right" id="footpager" align="center"></div>
                    </div>
                </div>
            </div>
        </div>
        <!-- /.box-body -->
    </section>
</div>
</body>
<script>
    var _keyword = '';
    var _page='1';
    var _size='10'
    $(function(){
        getlist(_keyword);
        //反选
        $('#allchecked').click(function(){
            $("[name = checkboxed]:checkbox").each(function () {
                $(this).prop("checked", !$(this).prop("checked"));
            });
        });
    });
    function getlist(_keyword)
    {
        $.ajax({
            type: 'post', cache: false,
            url:'{:url("admin/Fodder/getFodderImgList")}',
            data: {keyword:_keyword,page:_page,size:_size},
            success: function(data) {
                if(data.code=="0")
                {
                    $("#tb tr").remove();
                    $.each(data.info,function(index,item){
                        var html='<tr role="row" class="odd" id="tr_'+item.id+'">';
                        html+='<td style="vertical-align: middle;"><input name="checkboxed" value="'+item.id+'" type="checkbox" style="margin-left: 10px"></td>';
                        html+='<td style="vertical-align: middle;">'+item.img_list+'</td>';
                        html+='<td style="vertical-align: middle;">'+item.img_loca_name+'</td>';
                        html+='<td style="vertical-align: middle;">'+item.sumname+'</td>';
                        html+='<td style="vertical-align: middle;">'+item.childname+'</td>';
                        html+='<td style="vertical-align: middle;">'+item.poolname+'</td>';
                        html+='<td style="vertical-align: middle;">'+item.createtime+'</td>';
                        html+='<td style="vertical-align: middle;text-align: center">';
                        html+='<div class="btn-group">';
                        html+=' <button onclick="toedit('+item.id+')" title="编辑" class="btn" style="background: #18bc9c;color: #ffffff;"><i class="fa fa-edit"></i></button>';
                        html+='</div>';
                        html+='</td>';
                        html+='</tr>';
                        $("#tb").append(html);
                    });
                    $('.img_list').click(function(){
                        var $_this = $(this);
                        var _url = $_this.attr('src');
                        window.open(_url);
                    });
                    $('.img_list').mouseover(function(){
                        var $_this = $(this);
                        $_this.css('border','1px solid #d2d2d2');
                    });
                    $('.img_list').mouseout(function(){
                        var $_this = $(this);
                        $_this.css('border','0px');
                    });
                    table = $('#example1').DataTable({
                        "paging": false,
                        "searching": false,
                        "info": false,
                        "autoWidth": true,
                    });
                    layerPager(_page,_size,data.count,"footpager","footpagerbind");
                }
            },
            error: function() {
                alert("发生系统错误,请与管理员联系！");
            }
        });
    }
    function footpagerbind(cpage)
    {
        _page=cpage;
        table.destroy();
        getlist();
    }
    //搜索
    function search()
    {
        _page = 1;
        table.destroy();
        var keyword = $('#keyword').val();
        getlist(keyword);
    }
    //添加
    function toadd() {
        var _url = '{:url("admin/Fodder/addFodderImg")}';
        layerWindow('添加图片素材',_url,'50%','80%');
    }
    //编辑
    function toedit(_id)
    {
        var _url = '{:url("admin/Fodder/editFodderImg")}?id='+_id;
        layerWindow('编辑图片素材',_url,'50%','80%');
    }
    //删除
    function todel(_id){
        layerConfirm('是否删除',function(){
            var chk_value =[];
            $('input[name="checkboxed"]:checked').each(function(){
                chk_value.push($(this).val());
            });
            $.ajax({
                type: 'post',
                cache: false,
                url: '{:url("admin/Fodder/delFodderImg")}',
                data: {ids: chk_value},
                success: function(data){
                    if(data.code == 0){
                        layerAlert(data.msg,function () {
                            relist();
                        });
                    }else{
                        layerAlert(data.msg);
                    }
                }
            });
        },function(){
        })
    }

    function relist()
    {
        table.destroy();
        getlist(_keyword);
    }
</script>
</html>